import random

def get_participants():
    """获取参与者名单"""
    participants = []
    while True:
        name = input("请输入参与者姓名（输入 q 结束）：")
        if name == 'q':
            break
        participants.append(name)
    return participants

def draw_winners(participants, num_winners):
    """抽取获奖者"""
    if not participants:
        print("没有参与者，无法抽奖。")
        return []

    if num_winners > len(participants):
        print("获奖人数超过参与者人数，将抽取所有参与者。")
        num_winners = len(participants)

    winners = random.sample(participants, num_winners)
    return winners

def display_winners(winners):
    """输出结果"""
    if not winners:
        print("没有获奖者。")
        return

    print("获奖者名单：")
    for winner in winners:
        print(winner)

# 主程序
if __name__ == "__main__":
    participants = get_participants()
    try:
        num_winners = int(input("请输入要抽取的获奖人数："))
    except ValueError:
        print("输入错误，请输入数字。")
        exit()
    winners = draw_winners(participants, num_winners)
    display_winners(winners)
